//
//  AIFSetSubAccountPwdManager.m
//  PywSdk
//
//  Created by Jade on 16/4/22.
//  Copyright © 2016年 zero. All rights reserved.
//

#import "AIFSetSubAccountPwdManager.h"
#import "PywRSAUtil.h"

@implementation AIFSetSubAccountPwdManager

NSString *const SetSubAccountPwd_SIGN = @"sign";
NSString *const SetSubAccountPwd_TID = @"tid";
NSString *const SetSubAccountPwd_GAMEID = @"gameid";
NSString *const SetSubAccountPwd_ACCOUNT = @"account";
NSString *const SetSubAccountPwd_ACCOUNT_PWD = @"new_pwd";
NSString *const SetSubAccountPwd_PASSPORT = @"passport";
NSString *const SetSubAccountPwd_PASSPORT_TOKEN = @"passport_token";

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.child = self;
        self.paramSource = self;
        self.validate = self;
    }
    return self;
}


#pragma mark - ETAPIManager
- (NSString *)methodName
{
    return URL_SETSUBACCOUNTPWD;
}

- (ETAPIManagerRequestType)requestType
{
    return ETAPIManagerRequestTypePost;
}


- (NSString *)seriviceType
{
    return [PywAppInfo sharedAppInfo].seriviceType;
}

#pragma mark - ETAPIManagerParamSourceDelegate
- (NSDictionary *)paramsForApi:(ETApiBaseManager *)manager
{
    NSString *passport = [PywPlatformMain sharedPlatformMain].passport;
    NSString *passport_token = [PywPlatformMain sharedPlatformMain].passport_Token;
    
    NSString *account = self.account;
    NSString *new_pwd = [PywRSAUtil encryptString:self.account_pwd];
    
    NSString *gameid = [PywAppInfo sharedAppInfo].gameId;
    NSString *tid = [PywAppInfo sharedAppInfo].tid;
    NSString *apiSecret2 = [AppUtil getApiSecret2:tid apiSecret:[PywAppInfo sharedAppInfo].apisecret];
    NSString *sign = [NSString stringWithFormat:@"%@%@%@",passport,self.account_pwd,apiSecret2];
    sign = [PywCipherUtils md5:sign];
    
    MutableDictionary *param = [[MutableDictionary alloc] init];
    [param setObject:passport forKey:SetSubAccountPwd_PASSPORT];
    [param setObject:passport_token forKey:SetSubAccountPwd_PASSPORT_TOKEN];
    [param setObject:account forKey:SetSubAccountPwd_ACCOUNT];
    [param setObject:new_pwd forKey:SetSubAccountPwd_ACCOUNT_PWD];
    [param setObject:gameid forKey:SetSubAccountPwd_GAMEID];
    [param setObject:tid forKey:SetSubAccountPwd_TID];
    [param setObject:sign forKey:SetSubAccountPwd_SIGN];
    return param;
}

#pragma mark - ETAPIManagerValidator
- (BOOL)manager:(ETApiBaseManager *)manager isCorrectWithParamsData:(NSDictionary *)data{
    return YES;
}

- (BOOL)manager:(ETApiBaseManager *)manager isCorrectWithCallBackData:(NSDictionary *)data{
    return YES;
}
@end
